package com.ruoyi.project.test.genericity;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.redis.core.RedisCommand;

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.DoubleStream;

public class Genericity {

    class TransactionClazz{
        String name;
        Integer no;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getNo() {
            return no;
        }

        public void setNo(Integer no) {
            this.no = no;
        }

        @Override
        public String toString() {
            return "TransactionClazz{" +
                    "name='" + name + '\'' +
                    ", no=" + no +
                    '}';
        }
    }

    class TransactionClazz2 {
        Date startTime;
        Float maxtime;

        public Date getStartTime() {
            return startTime;
        }

        public void setStartTime(Date startTime) {
            this.startTime = startTime;
        }

        public Float getMaxtime() {
            return maxtime;
        }

        public void setMaxtime(Float maxtime) {
            this.maxtime = maxtime;
        }

        @Override
        public String toString() {
            return "TransactionClazz2{" +
                    "startTime=" + startTime +
                    ", maxtime=" + maxtime +
                    '}';
        }
    }

    class VastObject<T>{
        T first;
        T end;
        void setFirst(T first){
            this.first = first;
        }
        void setEnd(T end){
            this.end = end;
        }
        T getFirst(){
            return first;
        }
        T getEnd() {
            return end;
        }
        T create(T data){
            if (data instanceof TransactionClazz){
                System.out.println(((TransactionClazz) data).getName());
            }
            if (data instanceof TransactionClazz2){
                System.out.println(((TransactionClazz2) data).getStartTime());
            }
            return data;
        }
    }


    public static void main(String[] args) throws Exception {
        TransactionClazz transactionClazz = new Genericity().new TransactionClazz();
        TransactionClazz2 transactionClazz2 = new Genericity().new TransactionClazz2();
        TransactionClazz2 transactionClazz3 = new Genericity().new TransactionClazz2();
        VastObject vastObject = new Genericity().new VastObject<>();
        transactionClazz.setName("张的");
        transactionClazz.setNo(123);
        transactionClazz2.setStartTime(new Date());
        transactionClazz2.setMaxtime(3.9355f);
        transactionClazz3.setStartTime(new Date());
        transactionClazz3.setMaxtime(3.65f);
        vastObject.setFirst(transactionClazz);
        vastObject.setEnd(transactionClazz2);
        System.out.println(vastObject.create(transactionClazz).toString());
        System.out.println(vastObject.create(transactionClazz2).toString());
        List<TransactionClazz2> list = Lists.newArrayList();
        list.add(transactionClazz2);
//        list.add(transactionClazz3);

        DecimalFormat df_1 = new DecimalFormat("0.0");
        DecimalFormat df_3 = new DecimalFormat("0");
        DecimalFormat df_2 = new DecimalFormat("0.00");

        double spinSRate_avg = list.stream().mapToDouble(TransactionClazz2::getMaxtime).average().getAsDouble();
        System.out.println(spinSRate_avg);
        System.out.println(df_2.format(spinSRate_avg));
        System.out.println(NumberUtil.round(spinSRate_avg,2));

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.YEAR, 2042);

        Date endTime = calendar.getTime();
        System.out.println(DateUtil.formatDateTime(endTime));

//        String image = "http://39.100.57.247:9888/group1/M00/06/7E/J2Q592KVgAiALnalAABoACUb4sE462.xls";
        String image = "http://218.78.18.147:9090/neuron/2022-06-17/d1c7fd70-23e7-43b3-8ed4-9fbd5be63fba.jpg";

        System.out.println(Arrays.toString(image.split("http://218.78.18.147:9090/")[1].split("/")));

    }
}
